import Ship
import Ships.MinerFSM.SM_MINER
import ShipSprite
import os, sys, pygame, pygame.font
from pygame.color import THECOLORS
from pygame.locals import *
import coords
import imageLoader

# **
# *  'Miner', child of 'Ship', contains a Finite State Machine (FSM) and also responsibilities 
# *  for updating and drawing itself. It also Handles 'Singals' and directs 'Signals' and corresponding 
# *  MessageDispatcher Instances to the FSM. 'HipJoint' is an active agent whose States are encapsulated 
# *  and interchanged within its FSM, through communications with the MessageDispatcher.
# *
# * PUBLIC FEATURES:
# *    // Constructors
# *    def __init__(self, name, side, size, velocity, mass, speedMAX, forceMAX, turnRateMAX)
# *
# *    // Methods
# *    def getFSM(self)
# *    def handleSignal(self, msg, signal)
# *    def render(self)
# *    def update(self, msg, time)
# *
# *    COLLABORATORS:
# *    Ship
# *    Ships.MinerFSM.SM_MINER
# *
# * MODIFIED:
# */

class Miner(Ship.Ship):
    def __init__(self, position, map):
        Ship.Ship.__init__(self, position, map)
        self.minerals = 0
        self.MAX_Minerals = 15        
        self.FSM = Ships.MinerFSM.SM_MINER.SM_MINER(self)
        self.homeBase = [0,0]        
    
    def getFSM(self):
        return self.FSM
    
    def handleInfluence(self, writer, influence):
        #self.FSM.handleInfluence(writer, influence)
        pass
    
    def update(self):
        #print str(self.myGridCoords)
        self.FSM.update()

class MinerSprite(ShipSprite.ShipSprite):

   # We'll just accept the x-position here
   def __init__(self, position, map, screen):
      ShipSprite.ShipSprite.__init__(self, position, screen)
      self.ship = Ships.Miner.Miner(position, map)
      self.image, self.rect = imageLoader.load_image('Miner.gif', -1)
      self.lastCellCoords = [-1,-1]
      self.rect.topleft = position[0], position[1]


   def moveAlongPath(self):
           #print 'locationGrid:' + str(path.nodes[self.count].location.x) + ',' + str(path.nodes[self.count].location.y)
           #targetLocation = self.gridToScreen(path.nodes[self.count].location)
           #self.ship.setTarget(targetLocation)
        self.ship.position = self.gridToScreen(self.path.nodes[self.count].location)
           
        self.count+=1

           #print 'count:' + str(self.count)
        #self.draw()


   def gridToScreen(self, gridCoords):
       #gridCoords.x = 44+(gridCoords.x * 16)-14
       #gridCoords.y = 44+(gridCoords.y * 16)-14
       screenCoords = [(44+(gridCoords.x * 16)),(44+(gridCoords.y * 16))]
       return screenCoords
 

   def draw(self):
      self.ship.updateGridCoords()
      position = self.ship.getPosition()
      self.old = self.rect

      #positionX = position[0].pop()
      #positionY = position[1].pop()
      
      self.rect = self.rect.move(position[0] - self.rect.x, position[1] - self.rect.y)

   # The x-position remains the same
   def update(self):
      #self.ship.updateGridCoords()
      self.ship.update()
      
      self.draw()
